package com.leo.train.business.controller.admin;

import com.leo.train.business.dto.SeatQueryDto;
import com.leo.train.business.entity.Seat;
import com.leo.train.business.service.SeatService;
import com.leo.train.business.vo.SeatVo;
import com.leo.train.common.resp.CommonResp;
import com.leo.train.common.resp.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/seat")
public class AdminSeatController {
    @Autowired
    private SeatService seatService;

    /**
     * 新增
     * @param seat
     * @return
     */
    @PostMapping("/add")
    public CommonResp add(@RequestBody Seat seat) {
        seatService.save(seat);
        return new CommonResp<>();
    }

    /**
     *  修改
     *  @param seat
     *  @return
     */
    @PostMapping("/update")
    public CommonResp update(@RequestBody Seat seat) {
        seatService.save(seat);
        return new CommonResp<>();
    }

    /**
     * 删除
     * @param map
     * @return
     */
    @PostMapping("/delete")
    public CommonResp delete(@RequestBody Map<String,Long> map) {
        Long id = map.get("id");
        seatService.deleteById(id);
        return new CommonResp<>();
    }

    /**
     * 查询座位列表
     * @param seatQueryDto
     * @return
     */
    @GetMapping("/list")
    public CommonResp<PageResult<SeatVo>> list(SeatQueryDto seatQueryDto) {
        PageResult<SeatVo> pageResult = seatService.list(seatQueryDto);
        return new CommonResp<>(pageResult);
    }

    /**
     * 详情
     * @param id
     */
    @GetMapping("/detail")
    public CommonResp<SeatVo> detail(@RequestParam Long id) {
        SeatVo seatVo = seatService.detail(id);
        return new CommonResp<>(seatVo);
    }


}
